package com.caigou.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.caigou.service.PersonService;

import jiliang.purchase.demo.PersonObject;

public class addPersonServlet extends HttpServlet {
	/*
	 * 添加用户
	 * 
	 * **/

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	private PersonService PS = new PersonService();
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		
		/*
		 * xingming 姓名
		 * gonghao 工号
		 * phone 电话
		 * js_id 角色ID
		 * dw_id 单位ID
		 * mima 密码
		 * dendidl 本地登录
		 * **/
		String xingming = request.getParameter("xingming");
		String gonghao = request.getParameter("gonghao");
		String phone = request.getParameter("phone");
		String[] js_id = request.getParameterValues("js_id[]");
		
		String ji = ",";
		for(int i=0;i<js_id.length;i++)
		{
			ji+=js_id[i];
		}
		String dw_id = request.getParameter("dw_id");
		String mima = request.getParameter("mima");
		String dendidl = request.getParameter("bendidl");
		PersonObject PO = new PersonObject(gonghao,xingming,ji,dw_id,mima,dendidl,phone);
		PS.setPerson(PO);
		
		request.getRequestDispatcher("YongHuliebiaoServlet").forward(request, response);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request,response);
	}

}
